home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / private / pdcdisp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  43.3 KB  |  1,757 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #include <string.h>
  20. #define    CURSES_LIBRARY    1
  21. #include <curses.h>
  22.  
  23. #ifndef NO_MEMORY_H
  24. #include <memory.h>
  25. #endif
  26.  
  27. #ifdef UNIX
  28. #include <defs.h>
  29. #include <term.h>
  30. #endif
  31.  
  32. #ifdef PDCDEBUG
  33. char *rcsid_PDCdisp  = "$Id$";
  34. #endif
  35.  
  36. /*man-start*********************************************************************
  37.  
  38.   PDC_backchar()    - Visually erase character in window
  39.  
  40.   PDCurses Description:
  41.      This is a private PDCurses function
  42.  
  43.      This routine will visually erase a character.  It is called by
  44.      the PDCurses character I/O routines.
  45.  
  46.   PDCurses Return Value:
  47.      This routine will return OK upon success and otherwise ERR will be
  48.      returned.
  49.  
  50.   PDCurses Errors:
  51.      It is an error to pass a NULL WINDOW pointer.
  52.  
  53.   Portability:
  54.      PDCurses    int    PDC_backchar( WINDOW* w, char* ch, int* len );
  55.  
  56. **man-end**********************************************************************/
  57.  
  58. #ifdef THESE_FUNCTIONS_ARENT_USED
  59. /***********************************************************************/
  60. int    PDC_backchar(WINDOW *w, char *ch, int *len)
  61. /***********************************************************************/
  62. {
  63.     int    nbs = 0;
  64.     int    x = w->_curx;
  65.     int    ts = w->_tabsize;
  66.     chtype    s = (w->_y[w->_cury][x - 1] & CHR_MSK);
  67.     char*    p = c_strbeg;
  68.     bool    save_raw_out = _cursvar.raw_out;
  69.  
  70. #ifdef PDCDEBUG
  71.     if (trace_on) PDC_debug("PDC_backchar() - called\n");
  72. #endif
  73.  
  74.     if (w == (WINDOW *)NULL)
  75.         return( ERR );
  76.  
  77.     (*len)--;        /* Now we are zero relative */
  78.     (*len)--;        /* Now we are looking at the previous
  79.                  * character */
  80.     if( *len >= 0 ) {
  81.         nbs++;
  82.         /*
  83.          * Determine number of characters to erase...
  84.          */
  85.         if ((ch[*len] < ' ') || (s == 0x7f))    /* ctrl-char has size 2     */
  86.         {
  87.             nbs++;
  88.             (*len)--;
  89.         }
  90.  
  91.         if( *len >= 0 )
  92.         if (ch[*len] == '\t')    /* tabs are very special */
  93.         {
  94.             for (; p < ch; p++)
  95.             {
  96.                 if (*p == '\t')
  97.                     x = ((x / ts) + 1) * ts;
  98.                 else
  99.                 {
  100.                     if ((*p < ' ') || (*p == 0x7f))
  101.                         x += 2;
  102.                     else
  103.                         x++;
  104.                 }
  105.                 if (x >= w->_maxx)    /* go to next line? */
  106.                     x = 0;
  107.             }
  108.             if (!(w->_curx))
  109.                 nbs = w->_maxx - x;
  110.             else
  111.                 nbs = w->_curx - x;
  112.         }
  113.     }
  114.     if( *len < 0 )
  115.     {
  116.         beep();
  117.         *len = 0;
  118.     }
  119.     /*
  120.      * Erase the characters and update...
  121.      */
  122.     _cursvar.raw_out = FALSE;  /* ensure backspace handled in xlat mode */
  123.     while ( nbs-- > 0 )
  124.     {
  125.         if (w->_curx > 0)
  126.         {
  127. /*            waddstr(w, "\b \b");*/
  128.             mvwaddch(w, w->_cury, w->_curx-1, ' ');
  129.             wmove(w, w->_cury, w->_curx-1);
  130.         }
  131.         else
  132.         if (w->_cury)
  133.         {
  134.             mvwaddch(w, w->_cury - 1, w->_maxx - 1, ' ');
  135.             wmove(w, w->_cury - 1, w->_maxx - 1);
  136.         }
  137.     }
  138.     ch[*len] = '\0';
  139.     _cursvar.raw_out = save_raw_out;
  140.     wrefresh(w);
  141.     return( OK );
  142. }
  143.  
  144. /*man-start*********************************************************************
  145.  
  146.   PDC_chg_attr_pair()    - Writes character and attribute to physical screen
  147.  
  148.   PDCurses Description:
  149.      This is a private PDCurses function.
  150.  
  151.      Writes a single character 'chr' with attribute 'attr' to the
  152.      current cursor location.
  153.  
  154.      NOTE:    Though passed as 16 bit quantities, only the lower 8 bits
  155.          will be used to create a character/attribute pair.
  156.  
  157.   PDCurses Return Value:
  158.      This function returns OK on success and ERR on error.
  159.  
  160.   PDCurses Errors:
  161.      No errors are defined for this function under DOS.
  162.  
  163.      An ERR may be returned under FLEXOS if s_copy() fails.  See the
  164.      Flexos Programmer's Reference Manual for details on the error.
  165.  
  166.   Portability:
  167.      PDCurses    int PDC_chg_attr_pair( chtype chr, chtype attr );
  168.  
  169. **man-end**********************************************************************/
  170.  
  171. /***********************************************************************/
  172. int    PDC_chg_attr_pair(chtype chr, chtype attr)
  173. /***********************************************************************/
  174. {
  175.     extern unsigned    char atrtab[MAX_ATRTAB];
  176.     int    phys_attr=chtype_attr(attr);
  177.  
  178. #ifdef    OS2
  179. # ifdef  EMXVIDEO
  180.     int curCol, curRow,cell;
  181. # else
  182.     USHORT curCol, curRow, cell;
  183. # endif
  184. #endif
  185.  
  186. #ifdef    FLEXOS
  187.     UBYTE    c = (UBYTE) chr;
  188.     UBYTE    a = (UBYTE) phys_attr;
  189. #endif
  190.  
  191. #ifdef PDCDEBUG
  192.     if (trace_on) PDC_debug("PDC_chg_attr_pair() - called\n");
  193. #endif
  194.  
  195. #ifdef    FLEXOS
  196.     drect.r_row = PDC_get_cur_row();
  197.     drect.r_col = PDC_get_cur_col();
  198.     drect.r_nrow = 1;
  199.     drect.r_ncol = 1;
  200.  
  201.     sframe.fr_pl[0] = (UBYTE *) & c;
  202.     sframe.fr_pl[1] = (UBYTE *) & a;
  203.     sframe.fr_pl[2] = (UBYTE *) " ";
  204.     sframe.fr_nrow = 1;
  205.     sframe.fr_ncol = 1;
  206.     sframe.fr_use = 0x00;
  207.  
  208.     srect.r_col = 0;
  209.     srect.r_row = 0;
  210.     srect.r_nrow = 1;
  211.     srect.r_ncol = 1;
  212.  
  213.     retcode = s_copy(0x03, 0x01L, 0L, (far unsigned short *) &drect, (far unsigned short *) &sframe, (far unsigned short *) &srect);
  214.     return( (retcode < 0L) ? ERR : OK );
  215. #endif
  216.  
  217. #ifdef    DOS
  218.     regs.h.ah = 0x09;
  219.     regs.h.al = chr & A_CHARTEXT;
  220.     regs.h.bh = _cursvar.video_page;
  221.     regs.h.bl = (char)(phys_attr >> 8);
  222. # ifdef WATCOMC
  223.     regs.w.cx = 0x01;
  224. # else
  225.     regs.x.cx = 0x01;
  226. # endif
  227.     int86(0x10, ®s, ®s);
  228.     return( OK );
  229. #endif
  230.  
  231. #ifdef    OS2
  232.     /* find the current cursor position */
  233. # ifdef EMXVIDEO
  234.     cell = (int)((chr & A_CHARTEXT) | phys_attr);
  235.     v_getxy (&curCol, &curRow);
  236.     v_putline ((char*)&cell, curCol, curRow, 1);
  237. # else
  238.     cell = (USHORT)((chr & A_CHARTEXT) | phys_attr);
  239.     VioGetCurPos((PUSHORT) &curRow, (PUSHORT) &curCol, 0);
  240.     VioWrtNCell((PBYTE)&cell,1,curRow,curCol,0);
  241. # endif
  242.     return( OK );
  243. #endif
  244.  
  245. #ifdef UNIX
  246. /* INCOMPLETE - check attribute and output attr and/or color */
  247.     putchar(chr & A_CHARTEXT);
  248.     return(OK);
  249. #endif
  250. }
  251. #endif
  252.  
  253. /*man-start*********************************************************************
  254.  
  255.   PDC_chadd()      - Low level; Put a character to a window
  256.  
  257.   PDCurses Description:
  258.         This is a private PDCurses function.
  259.  
  260.         This routine will insert the character 'c' at the current cursor
  261.         position in the passed window.
  262.  
  263.         If 'xlat' is TRUE, PDC_chadd() will handle things in a cooked
  264.         manner (tabs, newlines, carriage returns, etc).  If 'xlat' is
  265.         FALSE, the characters are simply output directly.
  266.  
  267.         If 'advance' is TRUE, PDC_chadd() will move the current cusor position
  268.         appropriately. The *addch functions call PDC_chadd() with advance TRUE,
  269.         while the *insch functions call PDC_chadd() with advance FALSE.
  270.  
  271.         The normal curses routines (non-raw-output-mode) call PDC_chadd()
  272.         with 'xlat' TRUE.
  273.  
  274.   PDCurses Return Value:
  275.         This function returns OK on success and ERR on error.
  276.  
  277.   PDCurses Errors:
  278.         It is an error to call this function with a NULL window pointer.
  279.  
  280.   Portability:
  281.         PDCurses        int PDC_chadd( WINDOW* win, chtype ch, bool xlat, bool advance );
  282.  
  283. **man-end**********************************************************************/
  284.  
  285. /***********************************************************************/
  286. int    PDC_chadd(register WINDOW *win, chtype ch,bool xlat, bool advance)
  287. /***********************************************************************/
  288. {
  289.     int    retval = ERR;
  290.     int    x=0;
  291.     int    y=0;
  292.     int    newx=0;
  293.     chtype    attr=0, bktmp=0;
  294.     int    ts=0;
  295.  
  296. #ifdef PDCDEBUG
  297.     if (trace_on) PDC_debug("PDC_chadd() - called: char=%c attr=0x%x xlat=%d advance=%d\n",ch & A_CHARTEXT,ch & A_ATTRIBUTES,xlat,advance);
  298. #endif
  299.  
  300.     if (win    == (WINDOW *)NULL)
  301.         return(    retval );
  302.  
  303.     x    = win->_curx;
  304.     y    = win->_cury;
  305.     ts    = win->_tabsize;
  306.  
  307. /* if the incoming character doesn't have its own attribute
  308.    then    use the    current    attributes for the window.
  309.    if the incoming character has attributes but    not a colour
  310.    component, or the attributes    to the current attributes
  311.    for the window.
  312.    if the incoming character has a colour component use    the
  313.    attributes solely from the incoming character */
  314.  
  315.     if ((ch    & A_ATTRIBUTES)    == 0)
  316.        attr    = win->_attrs;
  317.     else
  318.        if ((ch & A_COLOR) == 0)
  319.           attr = (ch & A_ATTRIBUTES) | win->_attrs;
  320.        else
  321.           attr = (ch & A_ATTRIBUTES);
  322.  
  323.     ch    = (ch &    A_CHARTEXT);
  324.  
  325. /*  wrs (4/10/93)
  326. /*  apply the same sort of logic for the window background, in that it only */
  327. /*  takes precedence if other color attributes are not there and that */
  328. /*  the background character will only print if the printing character is */
  329. /*  blank. */
  330.  
  331.     if ((attr & A_COLOR) == 0)
  332.        attr = (attr | (win->_bkgd & A_ATTRIBUTES));
  333.     else {
  334.        bktmp = (win->_bkgd & A_COLOR);
  335.        attr = (attr | ( (win->_bkgd & A_ATTRIBUTES) ^ bktmp ));
  336.     }
  337.  
  338.     if ( ch == ' ' )
  339.         ch = ((win->_bkgd & A_CHARTEXT));
  340.  
  341.  
  342.     if ((y > win->_maxy) ||
  343.         (x > win->_maxx) ||
  344.         (y < 0) ||
  345.         (x < 0))
  346.     {
  347.         return(    retval );
  348.     }
  349.  
  350.     if (xlat)
  351.     {
  352.         switch (ch) {
  353.         case '\t':
  354.             for (newx = ((x    / ts) +    1) * ts; x < newx; x++)
  355.             {
  356.                 if (waddch(win,    ' ') ==    ERR)
  357.                 {
  358.                     return(    retval );
  359.                 }
  360.                 /*
  361.                  * if tab to next line
  362.                  */
  363.                 if (win->_curx == 0)
  364.                 {
  365.                     /*
  366.                      * exit    the loop
  367.                      */
  368.                     return(    OK );
  369.                 }
  370.             }
  371.             return(    OK );
  372.  
  373.         case '\n':
  374.             if (_cursvar.autocr && !(_cursvar.raw_out))
  375.             {
  376.                 /*
  377.                  * if lf -> crlf
  378.                  */
  379.                 x = 0;
  380.             }
  381.             wclrtoeol( win );
  382.             if ((y = PDC_newline(win, y)) < 0)
  383.                 return(    retval );
  384.             if (advance)
  385.               {
  386.                win->_cury =    y;
  387.                win->_curx =    x;
  388.               }
  389.             return(    OK );
  390.  
  391.         case '\r':
  392.             if (advance)
  393.                win->_curx =    x = 0;
  394.             return(    OK );
  395.  
  396.         case '\b':
  397.             if (--x    < 0)
  398.             {
  399.                 /*
  400.                  * no back over    left margin
  401.                  */
  402.                 x = 0;
  403.             }
  404.             if (advance)
  405.                win->_curx =    x;
  406.             return(    OK );
  407.  
  408.         case 0x7f:
  409.             if (waddch(win,    '^') ==    ERR)
  410.             {
  411.                 return(    retval );
  412.             }
  413.             retval = waddch(win, '?');
  414.             return(    retval );
  415.  
  416.         default:
  417.             break;
  418.         }        /* switch */
  419.  
  420.         if (ch < ' ')
  421.         {
  422.             /*
  423.              * handle control chars
  424.              */
  425.             if (waddch(win,    '^') ==    ERR)
  426.                 return(    retval );
  427.  
  428.             retval = (waddch(win, ch + '@'));
  429.             return(    retval );
  430.         }
  431.     }
  432.  
  433.     /*
  434.      *    Add the    attribute back into the    character.
  435.      */
  436.     ch    |= attr;
  437. /*********************************************************************/
  438. /* only change _firstch/_lastch if character to be added is different */
  439. /* to the character/attribute that is already in that position in the */
  440. /* window.                                                            */
  441. /* Removing this fixes display problems with different windows in the */
  442. /* same physical position. MH 20-03-93                                */
  443. /* Restored again.         MH 02-04-93                                */
  444. /*********************************************************************/
  445.     if (win->_y[y][x] !=    ch)
  446.     {
  447.         /*
  448.          * only    if data    change
  449.          */
  450.         if (win->_firstch[y] ==    _NO_CHANGE)
  451.         {
  452.             win->_firstch[y] = win->_lastch[y] = x;
  453.         }
  454.         else
  455.         {
  456.             if (x <    win->_firstch[y])
  457.             {
  458.                 win->_firstch[y] = x;
  459.             }
  460.             else
  461.             {
  462.                 if (x >    win->_lastch[y])
  463.                 {
  464.                     win->_lastch[y] = x;
  465.                 }
  466.             }
  467.         }
  468.     }
  469.     win->_y[y][x++] = ch;
  470.     if (x >= win->_maxx)
  471.     {
  472.         /*
  473.          * wrap    around test
  474.          */
  475.         x = 0;
  476.         if ((y = PDC_newline(win, y)) < 0)
  477.             return(    retval );
  478.     }
  479.     if (advance)
  480.       {
  481.        win->_curx =    x;
  482.        win->_cury =    y;
  483.       }
  484.     return(    OK );
  485. }
  486.  
  487. /*man-start*********************************************************************
  488.  
  489.   PDC_chg_attrs()    - Change attributes in a rectangle
  490.  
  491.   PDCurses Description:
  492.      This routine will change the attribute(s) from a starting (y,x)
  493.      position to an ending (y,x) position to the specified attribute.
  494.  
  495.   PDCurses Return Value:
  496.      This function returns OK on success and ERR on error.
  497.  
  498.   PDCurses Errors:
  499.      It is an error to call this function with a NULL window pointer.
  500.      It is also an error to pass rectangular coordinates that lay
  501.      outside of window.
  502.  
  503.   Portability:
  504.      PDCurses    int PDC_chg_attrs( WINDOW* w, chtype attr,
  505.                      int sy, int sx,
  506.                      int ey, int ex );
  507.  
  508. **man-end**********************************************************************/
  509.  
  510. /***********************************************************************/
  511. int    PDC_chg_attrs(WINDOW *w, chtype attr, int sy, int sx, int ey, int ex)
  512. /***********************************************************************/
  513. {
  514.     chtype    oldattr = w->_attrs;
  515.     int    c=0;
  516.     int    l=0;
  517.  
  518. #ifdef PDCDEBUG
  519.     if (trace_on) PDC_debug("PDC_chr_attrs() - called\n");
  520. #endif
  521.  
  522.     if (w == (WINDOW *)NULL)        return( ERR );
  523.     if (sy > w->_maxy)    return( ERR );
  524.     if (sx > w->_maxx)    return( ERR );
  525.     if (ey >= w->_maxy)    ey = w->_maxy - 1;
  526.     if (ex >= w->_maxx)    ex = w->_maxx - 1;
  527.  
  528.     wattrset(w, attr);
  529.     for (l = sy; l <= ey; l++)
  530.     {
  531.         for (c = sx; c <= ex; c++)
  532.             w->_y[l][c] = (w->_y[l][c] & A_CHARTEXT) | attr;
  533.  
  534.         if (w->_firstch[l] == _NO_CHANGE)
  535.         {
  536.             w->_firstch[l] = sx;
  537.             w->_lastch[l] = ex;
  538.         }
  539.         else
  540.         if (w->_firstch[l] != _NO_CHANGE)
  541.         {
  542.             if (sx < w->_firstch[l])
  543.                 w->_firstch[l] = sx;
  544.             if (ex > w->_lastch[l])
  545.                 w->_lastch[l] = ex;
  546.         }
  547.     }
  548.     w->_attrs = oldattr;
  549.     return( OK );
  550. }
  551.  
  552. /*man-start*********************************************************************
  553.  
  554.   PDC_chins()    - Low-level insert character in window
  555.  
  556.   PDCurses Description:
  557.      This is a private PDCurses routine.
  558.  
  559.      This routine provides the basic functionality for the X/Open
  560.      [mv][w]insch() routines.  The xlat flag indicates that normal
  561.      character translation is performed or not.  If not, then the
  562.      character is output as is.
  563.  
  564.      The 'xlat' flag is TRUE for the normal curses routines.
  565.  
  566.   PDCurses Return Value:
  567.      This function returns OK on success and ERR on error.
  568.  
  569.   PDCurses Errors:
  570.      It is an error to call this function with a NULL window pointer.
  571.  
  572.   Portability:
  573.      PDCurses    int PDC_chins( WINDOW* win, chtype c, bool xlat );
  574.  
  575. **man-end**********************************************************************/
  576.  
  577. /***********************************************************************/
  578. int    PDC_chins(WINDOW *win, chtype c, bool xlat)
  579. /***********************************************************************/
  580. {
  581.     int    retval = ERR;
  582.     int    x=0;
  583.     int    y=0;
  584.     int    maxx=0;
  585.     int    offset=0;
  586.     chtype *temp1;
  587.     char    ch    = (c & A_CHARTEXT);
  588.  
  589. #ifdef PDCDEBUG
  590.     if (trace_on) PDC_debug("PDC_chins() - called\n");
  591. #endif
  592.  
  593.     if (win == (WINDOW *)NULL)
  594.         return( retval );
  595.  
  596.     x    = win->_curx;
  597.     y    = win->_cury;
  598.     maxx    = win->_maxx;
  599.     offset    = 1;
  600.     temp1    = &win->_y[y][x];
  601.  
  602.     if ((ch < ' ') && xlat)
  603.     {
  604.         offset++;
  605.     }
  606.  
  607.     memmove( temp1+offset, temp1, (maxx - x -offset) * sizeof(chtype) );
  608.  
  609.     win->_lastch[y] = maxx-1;
  610.  
  611.     if ((win->_firstch[y] == _NO_CHANGE) ||
  612.         (win->_firstch[y] > x))
  613.     {
  614.         win->_firstch[y] = x;
  615.     }
  616.     /*
  617.      * PDC_chadd() fixes CTRL-chars too
  618.      */
  619.     retval = (PDC_chadd(win, c, xlat,FALSE));
  620.     return( retval );
  621. }
  622.  
  623. /*man-start*********************************************************************
  624.  
  625.   PDC_clr_scrn()    - Clears the physical screen and homes the cursor.
  626.  
  627.   PDCurses Description:
  628.      This is an internal routine called by the doupdate() routines.
  629.  
  630.   PDCurses Return Value:
  631.      This routine always returns OK.
  632.  
  633.   Portability:
  634.      PDCurses    int PDC_clr_scrn( WINDOW* win );
  635.  
  636. **man-end**********************************************************************/
  637.  
  638. /***********************************************************************/
  639. int    PDC_clr_scrn(WINDOW *win)
  640. /***********************************************************************/
  641. {
  642. #if defined(UNIX_WCLR)
  643.     chtype    attrs = win->_attrs;
  644. #else
  645.     chtype    attrs = win->_bkgd;
  646. #endif
  647.  
  648. #ifdef PDCDEBUG
  649.     if (trace_on) PDC_debug("PDC_clr_scrn() - called\n");
  650. #endif
  651.  
  652. #if defined(XCURSES)
  653.     XCurses_instruct(CURSES_CLEAR);
  654. #else
  655.     PDC_scroll(0, 0, LINES - 1, COLS - 1, 0, attrs);
  656.     PDC_gotoxy(0, 0);
  657. #endif
  658.  
  659.     return( OK );
  660. }
  661. #ifndef NO_MEMORY_H
  662. #include <memory.h>
  663. #endif
  664.  
  665. /*man-start*********************************************************************
  666.  
  667.   PDC_clr_update()    - Updates the screen with a full redraw.
  668.  
  669.   PDCurses Description:
  670.      Updates the screen by clearing it and then redraw it in its
  671.      entirety. If _cursvar.refrbrk is TRUE, and there is pending
  672.      input characters, the update will be prematurely terminated.
  673.  
  674.   PDCurses Return Value:
  675.      This routine returns ERR if it is unable to accomplish it's task.
  676.      This return value is ONLY under FLEXOS.
  677.  
  678.      The return value OK is returned if there were no errors.
  679.  
  680.   PDCurses Errors:
  681.      No errors are defined for this function.
  682.  
  683.   Portability:
  684.      PDCurses    int PDC_clr_update( WINDOW* s );
  685.  
  686. **man-end**********************************************************************/
  687.  
  688. /***********************************************************************/
  689. int    PDC_clr_update(WINDOW *s)
  690. /***********************************************************************/
  691. {
  692. register int    i=0,j=0;
  693.     WINDOW*    w=NULL;
  694. #if defined(UNIX)
  695.     chtype*    ch;
  696. #else
  697.     unsigned short*    ch;
  698. #endif
  699.     bool rc=FALSE;
  700.  
  701. #if defined(DOS)
  702. #  if SMALL || MEDIUM
  703. struct SREGS segregs;
  704. int ds=0;
  705. #  endif
  706. #endif
  707.  
  708. #ifdef    FLEXOS
  709.     char    line[80];
  710.     char    attr[80];
  711.     FFRAME    sframe;
  712.     RECT    drect,
  713.         srect;
  714. #endif
  715. #if defined(DOS) && defined(NDP)
  716.     int *VIDPOINT;
  717. #endif
  718.  
  719.     extern unsigned    char atrtab[MAX_ATRTAB];
  720.  
  721. /* the next two varaibales have been changed from chtype to unsigned short */
  722. /* as this is the correct datatype for a physical character/attribute */
  723.     unsigned short temp_line[256]; /* this should be enough for the maximum width of a screen. MH-920715 */
  724.     unsigned short chr;
  725.  
  726. #ifdef PDCDEBUG
  727.     if (trace_on) PDC_debug("PDC_clr_update() - called\n");
  728. #endif
  729.  
  730.     w = curscr;
  731.     if (w == (WINDOW *)NULL)
  732.         return( ERR );
  733. /*    if (_cursvar.full_redraw)
  734.         PDC_clr_scrn(s); *//* clear physical screen */
  735.  
  736.     s->_clear = FALSE;
  737.     for (i = 0; i < LINES; i++)    /* update physical screen */
  738.     {
  739.         if (s != w)    /* copy s to curscr */
  740.  
  741.             memcpy(w->_y[i], s->_y[i], COLS * sizeof(chtype));
  742.  
  743.         ch = temp_line; /* now have ch pointing to area to contain real attributes. MH-920715 */
  744.  
  745.  
  746. #if defined(DOS) || defined(OS2)
  747. #  if 0
  748.         memcpy(ch,s->_y[i],COLS*sizeof(chtype)); /* copy current line to temp_line. MH-920715 */
  749.         for (j=0;j<COLS;j++)          /* for each chtype in the line... */
  750.            {
  751.             chr = temp_line[j] & A_CHARTEXT;
  752.             temp_line[j] = chtype_attr(temp_line[j]) | chr;
  753.            }
  754. #  else
  755.         for (j=0;j<COLS;j++)          /* for each chtype in the line... */
  756.            {
  757.             chr = (unsigned short)(s->_y[i][j] & A_CHARTEXT);
  758.             temp_line[j] = chtype_attr(s->_y[i][j]) | chr;
  759.            }
  760. #  endif
  761. #endif
  762.  
  763.         if (_cursvar.direct_video)
  764.         {
  765. #ifdef    FLEXOS
  766.             PDC_split_plane(w, &line[0], &attr[0], i, 0, i, COLS);
  767. /* need to translate attr[] array to real attributes before displaying it. MH-920715 */
  768.             drect.r_row = i;
  769.             drect.r_col = 0;
  770.             drect.r_nrow = 1;
  771.             drect.r_ncol = COLS;
  772.  
  773.             sframe.fr_pl[0] = (UBYTE *) line;
  774.             sframe.fr_pl[1] = (UBYTE *) attr;
  775.             sframe.fr_nrow = 1;
  776.             sframe.fr_ncol = COLS;
  777.             sframe.fr_use = 0x03;
  778.  
  779.             srect.r_col = 0;
  780.             srect.r_row = 0;
  781.             srect.r_nrow = 1;
  782.             srect.r_ncol = COLS;
  783.  
  784.             s_copy(0x03, 0x01L, 0L, (far unsigned short *) &drect,
  785.                 (far unsigned short *) &sframe,
  786.                 (far unsigned short *) &srect);
  787. #endif
  788.  
  789. #ifdef    DOS
  790. #  ifdef GO32
  791.             dosmemput (ch, COLS * sizeof(unsigned short),
  792.                 (void *)_FAR_POINTER(_cursvar.video_seg,
  793.                 _cursvar.video_ofs + (i * COLS * sizeof(unsigned short))));
  794. #  else
  795. #    if    (SMALL || MEDIUM)
  796.         segread(&segregs);
  797.         ds = segregs.ds;
  798.         movedata(ds, (int)ch,
  799.                 _cursvar.video_seg,
  800.                 _cursvar.video_ofs + (i*COLS*sizeof(unsigned short)),
  801.                     (COLS * sizeof(unsigned short)));
  802. #    else
  803. /*
  804. #    ifdef    NDP
  805.             VIDPOINT = (int *) mapdev(MK_FP(_cursvar.video_seg,
  806.               _cursvar.video_ofs + (i * COLS * sizeof(unsigned short))),
  807.               (COLS * sizeof(unsigned short)));
  808.             memcpy(VIDPOINT, (int *) ch, (COLS * sizeof(unsigned short)));
  809. */
  810.             memcpy((void *)_FAR_POINTER(_cursvar.video_seg,
  811.               _cursvar.video_ofs + (i * COLS * sizeof(unsigned short))),
  812.                    ch, (COLS * sizeof(unsigned short)));
  813. #    endif
  814. #  endif
  815. #endif
  816.  
  817. #ifdef    OS2
  818. # ifdef EMXVIDEO
  819.                 v_putline ((char *)ch, 0, i, COLS);
  820. # else
  821.                 VioWrtCellStr ((PCH)ch, (USHORT)(COLS * sizeof(unsigned short)), (USHORT)i, 0, 0);
  822. # endif
  823. #endif
  824.         }
  825.         else
  826.         {
  827.  
  828. #ifdef UNIX
  829.             PDC_gotoxy(i, 0);
  830.             for (j = 0; j < COLS; j++)
  831.             {
  832.                 PDC_putc( (*ch & A_CHARTEXT), (*ch & A_ATTRIBUTES) );
  833.                 ch++;
  834.             }
  835. #endif
  836.  
  837. #if defined(DOS) || defined(OS2)
  838.             for (j = 0; j < COLS; j++)
  839.             {
  840.                 PDC_gotoxy(i, j);
  841.                 PDC_putc( (*ch & A_CHARTEXT), (*ch & A_ATTRIBUTES) >> 8 );
  842.                 ch++;
  843.             }
  844. #endif
  845.  
  846. #if defined(XCURSES)
  847.         XCurses_transform_line(w->_y[i],i,0,COLS);
  848. #endif
  849.  
  850.         }
  851.  
  852.         if (_cursvar.refrbrk && (_cursvar.cbreak || _cursvar.raw_inp)) 
  853.         {
  854.             rc = PDC_breakout();
  855.             if(rc) 
  856.                 break;
  857.         }
  858.  
  859.     }
  860. #if defined(XCURSES)
  861.     XCurses_wait_for_display();
  862. #endif
  863.     return( OK );
  864. }
  865.  
  866. /*man-start*********************************************************************
  867.  
  868.   PDC_cursor_on()    - Turns on the hardware cursor.
  869.  
  870.   PDCurses Description:
  871.      Turns on the hardware curses, it does nothing if it is already on.
  872.  
  873.   PDCurses Return Value:
  874.      Returns OK upon success, ERR upon failure.
  875.  
  876.   Portability:
  877.      PDCurses    int PDC_cursor_on( void );
  878.  
  879. **man-end**********************************************************************/
  880.  
  881. /***********************************************************************/
  882. int    PDC_cursor_on(void)
  883. /***********************************************************************/
  884. {
  885. #ifdef PDCDEBUG
  886.     if (trace_on) PDC_debug("PDC_cursor_on() - called\n");
  887. #endif
  888.  
  889. #ifndef UNIX
  890.     if    (!_cursvar.visible_cursor)
  891.     {
  892.         _cursvar.visible_cursor = TRUE;
  893. /*        PDC_fix_cursor(_cursvar.orig_emulation);*/
  894.         if (_cursvar.bogus_adapter)
  895.         {
  896.             PDC_set_cursor_mode((_cursvar.cursor & 0xff00) >> 8,
  897.                      (_cursvar.cursor & 0x00ff));
  898.         }
  899.         else
  900.         {
  901. #ifdef     OS2
  902.             PDC_set_cursor_mode((_cursvar.cursor & 0xff00) >> 8,
  903.                          (_cursvar.cursor & 0x00ff));
  904. #else
  905.             switch (_cursvar.adapter) {
  906.             case _MDA:
  907.             case _CGA:
  908.             case _EGACOLOR:
  909.             case _EGAMONO:
  910.             case _VGACOLOR:
  911.             case _VGAMONO:
  912.             case _MDS_GENIUS:
  913. /*                PDC_set_cursor_mode(_cursvar.font - 2, _cursvar.font - 1);*/
  914.                 PDC_set_cursor_mode((_cursvar.cursor & 0xff00) >> 8,
  915.                          (_cursvar.cursor & 0x00ff));
  916.                 break;
  917.             case _MCGACOLOR:
  918.             case _MCGAMONO:
  919. /*                PDC_set_cursor_mode(_cursvar.font - 1, _cursvar.font - 2);*/
  920.                 PDC_set_cursor_mode((_cursvar.cursor & 0xff00) >> 8,
  921.                          (_cursvar.cursor & 0x00ff));
  922.                 break;
  923.             case _FLEXOS:
  924.                 PDC_set_cursor_mode(_cursvar.visible_cursor, 0);
  925.                 break;
  926.             default:
  927.                 break;
  928.             }
  929. #endif
  930.         }
  931.     }
  932. #endif
  933.     return( OK );
  934. }
  935.  
  936. /*man-start*********************************************************************
  937.  
  938.   PDC_cursor_off()    - Turns off the hardware cursor.
  939.  
  940.   PDCurses Description:
  941.      Turns off the hardware curses, it does nothing if it is already off.
  942.  
  943.   PDCurses Return Value:
  944.      Returns OK upon success, ERR upon failure.
  945.  
  946.   PDCurses Errors:
  947.      ERR will be returned (in the case of FLEXOS) if the hardware cursor
  948.      can not be disabled.
  949.  
  950.   Portability:
  951.      PDCurses    int PDC_cursor_off( void );
  952.  
  953. **man-end**********************************************************************/
  954.  
  955. /***********************************************************************/
  956. int    PDC_cursor_off(void)
  957. /***********************************************************************/
  958. {
  959. #ifdef PDCDEBUG
  960.     if (trace_on) PDC_debug("PDC_cursor_off() - called\n");
  961. #endif
  962.  
  963. #ifndef UNIX
  964.     if    (_cursvar.visible_cursor)
  965.     {
  966.         _cursvar.visible_cursor = FALSE;
  967. #ifdef     OS2
  968.         PDC_set_cursor_mode(32, 33);    /* turn it off */
  969. #else
  970.         switch (_cursvar.adapter)
  971.         {
  972.         case _FLEXOS:
  973.             PDC_set_cursor_mode(_cursvar.visible_cursor, 0);
  974.             break;
  975.         default:
  976.             PDC_set_cursor_mode(32, 33);    /* turn it off */
  977.             break;
  978.         }
  979. #endif
  980.     }
  981. #endif
  982.     return( OK );
  983. }
  984.  
  985. /*man-start*********************************************************************
  986.  
  987.   PDC_fix_cursor()    - Fix the cursor start and stop scan lines (if necessary)
  988.  
  989.   PDCurses Description:
  990.      This is a private PDCurses routine.
  991.  
  992.      This routine will fix the cursor shape for certain video adapters.
  993.      Normally, the values used are correct, but some adapters choke.
  994.      The most noticable choke is on a monochrome adapter.  The "correct"
  995.      scan lines will result in the cursor being set in the middle of the
  996.      character cell, rather than at the bottom.
  997.  
  998.      The passed flag indicates whether the cursor is visible or not.
  999.  
  1000.      This only applies to the DOS platform.
  1001.  
  1002.   PDCurses Return Value:
  1003.      This function returns OK on success and ERR on error.
  1004.  
  1005.   PDCurses Errors:
  1006.      No errors are defined for this function.
  1007.  
  1008.   Portability:
  1009.      PDCurses    int PDC_fix_cursor( int flag );
  1010.  
  1011. **man-end**********************************************************************/
  1012.  
  1013. /***********************************************************************/
  1014. int    PDC_fix_cursor(int flag)
  1015. /***********************************************************************/
  1016. {
  1017. #ifdef    DOS
  1018.  
  1019. #ifdef PDCDEBUG
  1020.     if (trace_on) PDC_debug("PDC_fix_cursor() - called\n");
  1021. #endif
  1022.  
  1023. #ifdef    FLEXOS
  1024.     return( OK );
  1025. #endif
  1026.  
  1027.     if (_cursvar.bogus_adapter)
  1028.         return( OK );
  1029.  
  1030.     switch (_cursvar.adapter)
  1031.     {
  1032.     case _EGACOLOR:
  1033.     case _EGAMONO:
  1034.     case _MDS_GENIUS:        /* Some clones look like a Genius;-)  */
  1035.         if (flag & 0x01)
  1036.             setdosmembyte (0x487, getdosmembyte (0x487) | 0x01); /* Enable emulation */
  1037.         else
  1038.             setdosmembyte (0x487, getdosmembyte (0x487) & ~0x01); /* Disable emulation */
  1039.         break;
  1040.  
  1041.     case _VGACOLOR:
  1042.     case _VGAMONO:
  1043.         if (flag & 0x01)
  1044. #ifdef WATCOMC
  1045.             regs.w.ax = 0x1200;        /* Enable  emulation */
  1046. #else
  1047.             regs.x.ax = 0x1200;        /* Enable  emulation */
  1048. #endif
  1049.         else
  1050. #ifdef WATCOMC
  1051.             regs.w.ax = 0x1201;        /* Disable emulation */
  1052. #else
  1053.             regs.x.ax = 0x1201;        /* Disable emulation */
  1054. #endif
  1055.         regs.h.bl = 0x34;
  1056.         int86(0x10, ®s, ®s);
  1057.  
  1058.         break;
  1059.  
  1060.     case _MCGACOLOR:
  1061.     case _MCGAMONO:
  1062.     case _MDA:
  1063.     case _CGA:
  1064.     case _NONE:
  1065.     default:
  1066.         break;
  1067.     }
  1068.     return( OK );
  1069. #endif
  1070.  
  1071. #ifdef     OS2
  1072.         return( OK );
  1073. #endif
  1074.  
  1075. #ifdef     UNIX
  1076.         return( OK );
  1077. #endif
  1078. }
  1079. #ifdef UNIX
  1080. #include <defs.h>
  1081. #include <term.h>
  1082. #endif
  1083.  
  1084. /*man-start*********************************************************************
  1085.  
  1086.   PDC_gotoxy()    - position hardware cursor at (x, y)
  1087.  
  1088.   PDCurses Description:
  1089.      This is a private PDCurses routine.
  1090.  
  1091.      Moves the physical cursor to the desired address on the
  1092.      screen. We don't optimize here -- on a PC, it takes more time
  1093.      to optimize than to do things directly.
  1094.  
  1095.   PDCurses Return Value:
  1096.      This function returns OK on success and ERR on error.
  1097.  
  1098.   PDCurses Errors:
  1099.      No errors are defined for this function.
  1100.  
  1101.   Portability:
  1102.      PDCurses    int PDC_gotoxy( int row, int col );
  1103.  
  1104. **man-end**********************************************************************/
  1105.  
  1106. /***********************************************************************/
  1107. int    PDC_gotoxy(int row, int col)
  1108. /***********************************************************************/
  1109. {
  1110. #ifdef PDCDEBUG
  1111.     if (trace_on) PDC_debug("PDC_gotoxy() - called: row %d col %d\n",row,col);
  1112. #endif
  1113.  
  1114. #ifndef UNIX
  1115.     if ((_cursvar.cursrow == row) && (_cursvar.curscol == col))
  1116.         return( OK );
  1117. #endif
  1118.  
  1119. #ifdef    FLEXOS
  1120.     retcode = s_get(T_VIRCON, 0L, (char *) &vir, (long) sizeof(vir));
  1121.     if (retcode < 0L)
  1122.         return( ERR );
  1123.     vir.vc_cursor.pos_row = row;
  1124.     vir.vc_cursor.pos_col = col;
  1125.     retcode = s_set(T_VIRCON, 0L, (char *) &vir, (long) sizeof(vir));
  1126.     return( (retcode < 0L) ? ERR : OK );
  1127. #endif
  1128.  
  1129. #ifdef    DOS
  1130.     regs.h.ah = 0x02;
  1131.     regs.h.bh = _cursvar.video_page;
  1132.     regs.h.dh = (unsigned char) row;
  1133.     regs.h.dl = (unsigned char) col;
  1134.     int86(0x10, ®s, ®s);
  1135.     return( OK );
  1136. #endif
  1137.  
  1138. #ifdef    OS2
  1139. # ifdef EMXVIDEO
  1140.     v_gotoxy (col, row);
  1141. # else
  1142.     VioSetCurPos (row, col, 0);
  1143. # endif
  1144.     return(OK);
  1145. #endif
  1146.  
  1147. #ifdef UNIX
  1148.     if (cursor_address != NULL)
  1149.         {
  1150.         putp(tparm(cursor_address,row,col));
  1151.         }
  1152.     return(OK);
  1153. #endif
  1154.  
  1155. #if defined (XCURSES)
  1156.     XCurses_display_cursor(_cursvar.cursrow,_cursvar.curscol,
  1157.         curscr->_y[_cursvar.cursrow][_cursvar.curscol],
  1158.         row,col,curscr->_y[row][col]);
  1159.     return(OK);
  1160. #endif
  1161. }
  1162.  
  1163. /*man-start*********************************************************************
  1164.  
  1165.   PDC_newline()    - Advances 1 newline from supplied line number.
  1166.  
  1167.   PDCurses Description:
  1168.      This is a private PDCurses routine.
  1169.  
  1170.      Does line advance and returns the new cursor line.  If error,
  1171.      return -1.
  1172.  
  1173.   PDCurses Return Value:
  1174.      This function returns OK on success and ERR on error.
  1175.  
  1176.   PDCurses Errors:
  1177.      No errors are defined for this function.
  1178.  
  1179.   Portability:
  1180.      PDCurses    int PDC_newline( WINDOW* win, int lin );
  1181.  
  1182. **man-end**********************************************************************/
  1183.  
  1184. /***********************************************************************/
  1185. int    PDC_newline(WINDOW *win, int lin)
  1186. /***********************************************************************/
  1187. {
  1188. #ifdef PDCDEBUG
  1189.     if (trace_on) PDC_debug("PDC_newline() - called: line %d\n",lin);
  1190. #endif
  1191.  
  1192.     if (win == (WINDOW *)NULL)
  1193.         return( -1 );
  1194.  
  1195.     if (++lin > win->_bmarg)
  1196.     {
  1197.         lin--;
  1198.         if (win->_scroll)
  1199.         {
  1200.             scroll(win);
  1201.  
  1202. /* wrs -- 7/11/93 ** it seems that System V Curses automatically refreshes
  1203.  *                   a window when scrolling occurs via a newline.  This
  1204.  *                   could be a feature that isn't intended, but I'll
  1205.  *                   implement it here as well for consistency.
  1206.  */
  1207.              wrefresh(win);
  1208.         }
  1209.         else
  1210.             return( -1 );
  1211.     }
  1212.     return( lin );
  1213. }
  1214.  
  1215. /*man-start*********************************************************************
  1216.  
  1217.   PDC_putc()    - Output a character in the current attribute.
  1218.  
  1219.   PDCurses Description:
  1220.      This is a private PDCurses routine.
  1221.  
  1222.      Outputs character 'chr' to screen in tty fashion. If a colour
  1223.      mode is active, the character is written with colour 'colour'.
  1224.  
  1225.   PDCurses Return Value:
  1226.      This function returns OK on success and ERR on error.
  1227.  
  1228.   PDCurses Errors:
  1229.      No errors are defined for this function.
  1230.  
  1231.   Portability:
  1232.      PDCurses    int PDC_putc( chtype character, chtype color );
  1233.  
  1234. **man-end**********************************************************************/
  1235.  
  1236. /***********************************************************************/
  1237. int    PDC_putc( chtype character, chtype color )
  1238. /***********************************************************************/
  1239. {
  1240. #ifdef    OS2
  1241.     int curRow=0, curCol=0;
  1242. # ifdef EMXVIDEO
  1243.     char Cell[2];
  1244. # endif
  1245. #endif
  1246.  
  1247. #ifdef UNIX
  1248. static chtype last_attribute=0;
  1249. #  ifdef CHTYPE_LONG
  1250. static bool last_acs=FALSE;
  1251. #  endif
  1252. static int curses_to_ansi[] = {0,4,2,6,1,5,3,7};
  1253. short fore=0,back=0;
  1254. #endif
  1255.  
  1256. #ifdef PDCDEBUG
  1257.     if (trace_on) PDC_debug("PDC_putc() - called:char=%c attrib=0x%x color=0x%x\n",character & A_CHARTEXT,character & A_ATTRIBUTES,color);
  1258. #endif
  1259.  
  1260. #ifdef    FLEXOS
  1261.     retcode = s_write(0x00, 0x01L, (_far char *) &character, 1L, 0);
  1262.     return( (retcode < 0L) ? ERR : OK );
  1263. #endif
  1264.  
  1265. #ifdef    DOS
  1266.     regs.h.ah = 0x09;    /* Avoid screen wrap.  Don't advance cursor. */
  1267.     regs.h.al = (unsigned char) (character & A_CHARTEXT);
  1268.     regs.h.bh = _cursvar.video_page;
  1269.     regs.h.bl = (unsigned char) (color);
  1270. #ifdef WATCOMC
  1271.     regs.w.cx = 1;
  1272. #else
  1273.     regs.x.cx = 1;
  1274. #endif
  1275.     int86(0x10, ®s, ®s);
  1276.     return( OK );
  1277. #endif
  1278.  
  1279. #ifdef    OS2
  1280.     PDC_get_cursor_pos (&curRow, &curCol);
  1281. # ifdef EMXVIDEO
  1282.     Cell[0] = (char)character;
  1283.     Cell[1] = (char)color;
  1284.     v_putline (Cell, curCol, curRow, 1);
  1285. # else
  1286.     VioWrtTTY ((PCH)&character, 1, 0);
  1287.     VioWrtNAttr ((PBYTE)&color, 1, (USHORT)curRow, (USHORT)curCol, 0);
  1288.     PDC_gotoxy (curRow, curCol);
  1289. # endif
  1290.     return( OK );
  1291. #endif
  1292.  
  1293. #ifdef UNIX
  1294.     if (last_attribute != color)
  1295.         {
  1296.         if (exit_attribute_mode != NULL)
  1297.             putp(exit_attribute_mode);
  1298.         last_attribute = color;
  1299.         if ((color & A_COLOR) && has_colors())
  1300.             {
  1301.             pair_content(PAIR_NUMBER(color),&fore,&back);
  1302.             putp(tparm(set_foreground,curses_to_ansi[fore]));
  1303.             putp(tparm(set_background,curses_to_ansi[back]));
  1304.             }
  1305.         if (color & A_BOLD)
  1306.             if (enter_bold_mode != NULL)
  1307.                 putp(enter_bold_mode);
  1308.         if (color & A_BLINK)
  1309.             if (enter_blink_mode != NULL)
  1310.                 putp(enter_blink_mode);
  1311.         if (color & A_REVERSE)
  1312.             if (enter_reverse_mode != NULL)
  1313.                 putp(enter_reverse_mode);
  1314. #ifdef CHTYPE_LONG
  1315.         if (color & A_STANDOUT)
  1316.             if (enter_standout_mode != NULL)
  1317.                 putp(enter_standout_mode);
  1318.         if (color & A_ALTCHARSET)
  1319.             {
  1320.             if (last_acs == FALSE)
  1321.                 if (enter_alt_charset_mode != NULL)
  1322.                     putp(enter_alt_charset_mode);
  1323.             last_acs = TRUE;
  1324.             }
  1325.         else
  1326.             {
  1327.             last_acs = FALSE;
  1328.             if (exit_alt_charset_mode != NULL)
  1329.                 putp(exit_alt_charset_mode);
  1330.             }
  1331. #endif
  1332.         }
  1333.     putchar(character & A_CHARTEXT);
  1334.     return( OK );
  1335. #endif
  1336. }
  1337.  
  1338. /*man-start*********************************************************************
  1339.  
  1340.   PDC_putctty()    - Output a character and attribute in TTY fashion.
  1341.  
  1342.   PDCurses Description:
  1343.      This is a private PDCurses routine.
  1344.  
  1345.      Outputs character 'chr' to screen in tty fashion. If a colour
  1346.      mode is active, the character is written with colour 'colour'.
  1347.  
  1348.      This function moves the physical cursor after writing so the
  1349.      screen will scroll if necessary.
  1350.  
  1351.   PDCurses Return Value:
  1352.      This function returns OK on success and ERR on error.
  1353.  
  1354.   PDCurses Errors:
  1355.      No errors are defined for this function.
  1356.  
  1357.   Portability:
  1358.      PDCurses    int PDC_putctty( chtype character, chtype color );
  1359.  
  1360. **man-end**********************************************************************/
  1361.  
  1362. /***********************************************************************/
  1363. int    PDC_putctty( chtype character, chtype color )
  1364. /***********************************************************************/
  1365. {
  1366. #ifdef    OS2
  1367.     int curRow=0, curCol=0;
  1368. #endif
  1369.  
  1370. #ifdef PDCDEBUG
  1371.     if (trace_on) PDC_debug("PDC_putctty() - called\n");
  1372. #endif
  1373.  
  1374. #ifdef    FLEXOS
  1375.     retcode = s_write(0x00, 0x01L, (_far char *) &character, 1L, 0);
  1376.     return( (retcode < 0L) ? ERR : OK );
  1377. #endif
  1378.  
  1379. #ifdef    DOS
  1380.     regs.h.ah = 0x0e;    /* Write in TTY fashion, advance cursor. */
  1381.     regs.h.al = (unsigned char) (character & A_CHARTEXT);
  1382.     regs.h.bh = _cursvar.video_page;
  1383.     regs.h.bl = (unsigned char) ((color & A_ATTRIBUTES) >> 8);
  1384.     int86(0x10, ®s, ®s);
  1385.     return( OK );
  1386. #endif
  1387.  
  1388. #ifdef    OS2
  1389.     PDC_get_cursor_pos (&curRow, &curCol);
  1390. # ifdef EMXVIDEO
  1391.     v_attrib (color);
  1392.     v_putc (character);
  1393. # else
  1394.     VioWrtTTY ((PCH)&character, 1, 0);
  1395.     VioWrtNAttr ((PBYTE)&color, 1, (USHORT)curRow, (USHORT)curCol, 0);
  1396. # endif
  1397.     return( OK );
  1398. #endif
  1399.  
  1400. #ifdef UNIX
  1401. /* INCOMPLETE */
  1402.     return( OK );
  1403. #endif
  1404. }
  1405.  
  1406. /*man-start*********************************************************************
  1407.  
  1408.   PDC_scroll()    - low level screen scroll
  1409.  
  1410.   PDCurses Description:
  1411.      Scrolls a window in the current page up or down. Urow, lcol,
  1412.      lrow, rcol are the window coordinates.    Lines is the number of
  1413.      lines to scroll. If 0, clears the window, if < 0 scrolls down,
  1414.      if > 0 scrolls up.  Blanks areas that are left, and sets
  1415.      character attributes to attr. If in a colour graphics mode,
  1416.      fills them with the colour 'attr' instead.
  1417.  
  1418.   PDCurses Return Value:
  1419.      The PDC_scroll() function returns OK on success otherwise ERR is returned.
  1420.  
  1421.   PDCurses Errors:
  1422.      An error will only be returned on the Flexos platform if s_copy()
  1423.      fails.
  1424.  
  1425.   Portability:
  1426.      PDCurses    int PDC_scroll( int urow, int lcol, int rcol,
  1427.                       int nlines, chtype attr );
  1428.  
  1429. **man-end**********************************************************************/
  1430.  
  1431. /***********************************************************************/
  1432. int    PDC_scroll(int urow, int lcol, int lrow, int rcol, int nlines, chtype attr)
  1433. /***********************************************************************/
  1434. {
  1435.     extern unsigned    char atrtab[MAX_ATRTAB];
  1436.     int    phys_attr=chtype_attr(attr);
  1437. #ifdef    FLEXOS
  1438.     int    srow=0;
  1439.     int    scol=0;
  1440.     int    drow=0;
  1441.     int    dcol=0;
  1442.     int    nrows=0;
  1443.     int    ncols=0;
  1444.     char    blank = (char) _cursvar.blank;
  1445. #endif
  1446.  
  1447. #ifdef    OS2
  1448. # ifndef EMXVIDEO
  1449.     USHORT ch=(phys_attr | _cursvar.blank);
  1450. # endif
  1451. #endif
  1452.  
  1453. #ifdef PDCDEBUG
  1454.     if (trace_on) PDC_debug("PDC_scroll() - called: urow %d lcol %d lrow %d rcol %d nlines %d\n",urow,lcol,lrow,rcol,nlines);
  1455. #endif
  1456.  
  1457. #ifdef    FLEXOS
  1458.     if (nlines == 0)
  1459.     {
  1460.         sframe.fr_pl[0] = (UBYTE *) & blank;
  1461.         sframe.fr_pl[1] = (UBYTE *) & attr;
  1462.         sframe.fr_pl[2] = (UBYTE *) " ";
  1463.         sframe.fr_nrow = 1;
  1464.         sframe.fr_ncol = 1;
  1465.         sframe.fr_use = 0x00;
  1466.         nrows = lrow;
  1467.         ncols = rcol;
  1468.         srow = drow = 0;
  1469.         scol = dcol = 0;
  1470.     }
  1471.     else
  1472.     if (nlines < 0)
  1473.     {
  1474.         srow = urow;
  1475.         scol = lcol;
  1476.         drow = lrow;
  1477.         dcol = rcol;
  1478.     }
  1479.     else
  1480.     if (nlines > 0)
  1481.     {
  1482.         srow = urow;
  1483.         scol = lcol;
  1484.         drow = lrow;
  1485.         dcol = lcol;
  1486.     }
  1487.  
  1488.     drect.r_row = drow;
  1489.     drect.r_col = dcol;
  1490.     drect.r_nrow = nrows;
  1491.     drect.r_ncol = ncols;
  1492.  
  1493.     srect.r_col = scol;
  1494.     srect.r_row = srow;
  1495.     srect.r_nrow = nrows;
  1496.     srect.r_ncol = ncols;
  1497.  
  1498.     if (nlines != 0)
  1499.         retcode = s_copy(0x03, 0x01L, 0L, (far unsigned short *) &drect, 0L, (far unsigned short *) &srect);
  1500.     else
  1501.         retcode = s_copy(0x03, 0x01L, 0L, (far unsigned short *) &drect, (far unsigned short *) &sframe, (far unsigned short *) &srect);
  1502.     return( (retcode < 0L) ? ERR : OK );
  1503. #endif
  1504.  
  1505. #ifdef    DOS
  1506.     if (nlines >= 0)
  1507.     {
  1508.         regs.h.ah = 0x06;
  1509.         regs.h.al = (unsigned char) nlines;
  1510.     }
  1511.     else
  1512.     {
  1513.         regs.h.ah = 0x07;
  1514.         regs.h.al = (unsigned char) (-nlines);
  1515.     }
  1516.     regs.h.bh = (unsigned char)(phys_attr >> 8);
  1517.     regs.h.ch = (unsigned char) urow;
  1518.     regs.h.cl = (unsigned char) lcol;
  1519.     regs.h.dh = (unsigned char) lrow;
  1520.     regs.h.dl = (unsigned char) rcol;
  1521.     int86(0x10, ®s, ®s);
  1522.     return( OK );
  1523. #endif
  1524.  
  1525. #ifdef    OS2
  1526. # ifdef EMXVIDEO
  1527.     v_attrib (phys_attr);
  1528.     if (nlines > 0)
  1529.         v_scroll (lcol, urow, rcol, lrow, nlines, V_SCROLL_UP);
  1530.     else
  1531.         if (nlines < 0)
  1532.             v_scroll (lcol, urow, rcol, lrow, -nlines, V_SCROLL_DOWN);
  1533.         else    /* this clears the whole screen */
  1534.             v_scroll (lcol, urow, rcol, lrow, -1, V_SCROLL_CLEAR);
  1535. # else
  1536.     if (nlines > 0)
  1537.         VioScrollUp(urow, lcol, lrow, rcol, nlines, (PBYTE)&ch, 0);
  1538.     else
  1539.         if (nlines < 0)
  1540.             VioScrollDn(urow, lcol, lrow, rcol, nlines, (PBYTE)&ch, 0);
  1541.         else
  1542. /* this clears the whole screen ?? */
  1543.             VioScrollUp(0, 0, -1, -1, -1, (PBYTE)&ch, 0);
  1544. # endif
  1545. #endif
  1546.  
  1547. #ifdef UNIX
  1548. /* INCOMPLETE */
  1549. #endif
  1550. }
  1551.  
  1552. /*man-start*********************************************************************
  1553.  
  1554.   PDC_transform_line()    - display a physical line of the screen
  1555.  
  1556.   PDCurses Description:
  1557.      This is a private PDCurses function.
  1558.  
  1559.      Updates the given physical line to look like the corresponding
  1560.      line in _curscr.
  1561.  
  1562.   PDCurses Return Value:
  1563.      This routine returns TRUE if a premature refresh end
  1564.      is allowed, and there is an input character pending.  Otherwise,
  1565.      FALSE is returned.
  1566.  
  1567.   PDCurses Errors:
  1568.      No errors are defined for this routine.
  1569.  
  1570.   Portability:
  1571.      PDCurses    bool    PDC_transform_line( int lineno );
  1572.  
  1573. **man-end**********************************************************************/
  1574.  
  1575. /***********************************************************************/
  1576. bool    PDC_transform_line(register int lineno)
  1577. /***********************************************************************/
  1578. {
  1579. #if defined (MSC) && defined (DOS)
  1580. chtype*    dstp=NULL;
  1581. chtype*    srcp=NULL;
  1582. #else
  1583. register chtype*    dstp=NULL;
  1584. register chtype*    srcp=NULL;
  1585. #endif
  1586.  
  1587. #ifdef DOS
  1588. #if SMALL || MEDIUM
  1589. struct SREGS segregs;
  1590. int ds=0;
  1591. #endif
  1592. #endif
  1593.  
  1594.     int    x=0;
  1595.     int    endx=0;
  1596.     int    len=0;
  1597. #if defined(DOS) && defined(NDP)
  1598.     int *VIDPOINT;
  1599. #endif
  1600.     extern unsigned    char atrtab[MAX_ATRTAB];
  1601.  
  1602. #if defined(DOS) || defined(OS2)
  1603.     unsigned short temp_line[256]={0}; /* this should be enough for the maximum width of a screen. MH-920715 */
  1604.     unsigned short chr=0;
  1605.     unsigned short*    ch=NULL;
  1606. #else
  1607.     chtype temp_line[256]={0}; /* this should be enough for the maximum width of a screen. MH-920715 */
  1608.     chtype chr=0;
  1609.     chtype*    ch=NULL;
  1610. #endif
  1611.  
  1612.     register int j=0;
  1613.     bool rc=FALSE;
  1614.  
  1615. #ifdef    FLEXOS
  1616.     char    line[80];
  1617.     char    attr[80];
  1618.     FFRAME    sframe;
  1619.     RECT    drect;
  1620.     RECT    srect;
  1621. #endif
  1622.  
  1623. #ifdef PDCDEBUG
  1624.     if (trace_on) PDC_debug("PDC_transform_line() - called\n");
  1625. #endif
  1626.  
  1627.     if (curscr == (WINDOW *)NULL)
  1628.         return( FALSE );
  1629.  
  1630.     x = curscr->_firstch[lineno];
  1631.     endx = curscr->_lastch[lineno];
  1632.     dstp = curscr->_y[lineno] + x;
  1633.     srcp = curscr->_y[lineno] + x;
  1634.     len = endx-x+1;
  1635.  
  1636.     ch = temp_line; /* now have ch pointing to area to contain real attributes. MH-920715 */
  1637.  
  1638. /* replace the attribute part of the chtype with the actual colour value */
  1639. /* replacing the number that points to the actual colour value.          */
  1640.  
  1641. #if defined(DOS) || defined(OS2)
  1642. #  if 0
  1643.         memcpy(ch, srcp, len * sizeof(chtype));
  1644.     for (j=0;j<len;j++)          /* for each chtype in the line... */
  1645.        {
  1646.         chr = temp_line[j] & A_CHARTEXT;
  1647.         temp_line[j] = chtype_attr(temp_line[j]) | chr;
  1648.        }
  1649. #  else
  1650.     for (j=0;j<len;j++)          /* for each chtype in the line... */
  1651.        {
  1652.         chr = *(srcp+j) & A_CHARTEXT;
  1653.         temp_line[j] = chtype_attr(*(srcp+j)) | chr;
  1654.        }
  1655. #  endif
  1656. #endif
  1657.  
  1658.     if (_cursvar.direct_video)
  1659.     {
  1660.  
  1661. #if IS_THIS_REALLY_NEEDED
  1662.         memcpy(dstp, srcp, len * sizeof(chtype));
  1663. #endif
  1664.  
  1665. #ifdef    FLEXOS
  1666.         _split_plane(curscr, &line[0], &attr[0], lineno, x, lineno, endx);
  1667.  
  1668.         drect.r_row = lineno;
  1669.         drect.r_col = x;
  1670.         drect.r_nrow = 1;
  1671.         drect.r_ncol = len;
  1672.  
  1673.         sframe.fr_pl[0] = (UBYTE *) line;
  1674.         sframe.fr_pl[1] = (UBYTE *) attr;
  1675.         sframe.fr_nrow = 1;
  1676.         sframe.fr_ncol = len;
  1677.         sframe.fr_use = 0x03;
  1678.  
  1679.         srect.r_col = 0;
  1680.         srect.r_row = 0;
  1681.         srect.r_nrow = 1;
  1682.         srect.r_ncol = len;
  1683.  
  1684.         s_copy(0x03, 0x01L, 0L, (far unsigned short *) &drect,
  1685.             (far unsigned short *) &sframe, (far unsigned
  1686.             short *) &srect);
  1687.  
  1688. #endif
  1689.  
  1690. #ifdef    DOS
  1691. #  ifdef GO32
  1692.         dosmemput (ch, len * sizeof(unsigned short),
  1693.             (void *)_FAR_POINTER(_cursvar.video_seg,
  1694.             _cursvar.video_ofs + (((lineno * curscr->_maxx) + x) * sizeof(unsigned short))));
  1695. #  else
  1696. #    if    SMALL || MEDIUM
  1697.         segread(&segregs);
  1698.         ds = segregs.ds;
  1699.         movedata(ds,(int)ch,
  1700.             _cursvar.video_seg,
  1701.             _cursvar.video_ofs+(((lineno*curscr->_maxx)+x)*sizeof(unsigned short)),
  1702.                 len * sizeof(unsigned short));
  1703. #    else
  1704.         memcpy((void *)_FAR_POINTER(_cursvar.video_seg,
  1705.                  _cursvar.video_ofs + (((lineno * curscr->_maxx) + x) * sizeof(unsigned short))),
  1706.                ch, len * sizeof(unsigned short));
  1707. #    endif
  1708. #  endif
  1709. #endif
  1710.  
  1711. #ifdef    OS2
  1712. # ifdef EMXVIDEO
  1713.                     v_putline ((char*)ch, x, lineno, len);
  1714. # else
  1715.                     VioWrtCellStr ((PCH)ch, (USHORT)(len*sizeof(unsigned short)), (USHORT)lineno, (USHORT)x, 0);
  1716. # endif
  1717. #endif
  1718.     }
  1719.     else
  1720.     {
  1721.  
  1722. #ifdef UNIX
  1723.         PDC_gotoxy(lineno,x);
  1724.         for (; x <= endx; x++)
  1725.         {
  1726.             PDC_putc( (*ch & A_CHARTEXT),(*ch & A_ATTRIBUTES) );
  1727.             ch++;
  1728.         }
  1729. #endif
  1730.  
  1731. #if defined(DOS) || defined(OS2)
  1732.         for (; x <= endx; x++)
  1733.         {
  1734.             PDC_gotoxy(lineno, x);
  1735.             PDC_putc( (*ch & A_CHARTEXT),(*ch & A_ATTRIBUTES) >> 8 );
  1736.             ch++;
  1737.         }
  1738. #endif
  1739.  
  1740. #if defined(XCURSES)
  1741.         XCurses_transform_line(dstp,lineno,x,len);
  1742. #endif
  1743.  
  1744.     }
  1745.     curscr->_firstch[lineno] = _NO_CHANGE;
  1746.     curscr->_lastch[lineno] = _NO_CHANGE;
  1747.  
  1748.     if (_cursvar.refrbrk && (_cursvar.cbreak || _cursvar.raw_inp)) 
  1749.     {
  1750.         rc = PDC_breakout();
  1751.         if(rc) 
  1752.             return(TRUE);
  1753.     }
  1754.     return(FALSE);
  1755. }
  1756.